<!DOCTYPE html>
<html lang="zh-cmn-Hans">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,viewport-fit=cover">
    <title>注册中</title>
    <link rel="stylesheet" href="/static/css/weui.css" />
    <link rel="stylesheet" href="/static/css/example.css" />
</head>

<body ontouchstart>
    <script type="text/html" id="tpl_home">
    <div class='page'>
        <div id="loadingToast" style="opacity: 0; display: none;">
            <div class="weui-mask_transparent">
            </div>
            <div class="weui-toast">
                <i class="weui-loading weui-icon_toast"></i>
                <p class="weui-toast__content" id="flag">注册中</p>
            </div>
        </div>
    </div>
    
            <script src="/static/js/jquery.min.js"></script>
            <script src="/static/js/weui.min.js"></script>
            <script type="text/javascript" src="/static/js/jweixin-1.4.0.js"></script>         
            <script src="/static/js/zepto.min.js"></script>
            <script src="/static/js/example.js"></script>
            <!-- <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>-->  
            
            
            <script type="text/javascript">
                $(function() {

                    function getQueryString(name) {
                        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
                        var r = decodeURI(window.location.search).substr(1).match(reg);
                        if (r != null) return (r[2]);
                        return null;
                    };

                    $(document).ready(function() {
                        var area = getQueryString('area');
                        var deviceid = getQueryString('device');
                        var code = getQueryString('code');
                        var passwd = getQueryString('passwd');

                        var $loadingToast = $('#loadingToast');
                        $loadingToast.fadeIn(100);
                        setTimeout(function () {
                            $loadingToast.fadeOut(100);
                        }, 2000);

                        console.log(area)
                        console.log(deviceid)
                        console.log(code)
                        console.log(passwd)
                        //alert(code)

                        // 根据deviceid和code 获取设备情况
                        $.ajax({
                            url: 'http://gzh.zjnnhj.com/niuneng/userRegister',
                            type: "post",
                            data: JSON.stringify({
                                'area': parseInt(area),
                                'deviceid': deviceid,
                                'code': code,
                                'passwd': passwd
                            }),
                            dataType: "json",
                            success: function(data) {
                                data = JSON.parse(data)
                                if (data.errcode == 0){
                                    alert('注册成功')
                                    // 注册成功推出页面
                                    setTimeout(function() {
                                        //这个可以关闭安卓系统的手机
                                        document.addEventListener(
                                            "WeixinJSBridgeReady",
                                            function() {
                                                WeixinJSBridge.call("closeWindow");
                                            },
                                            false
                                        );
                                            //这个可以关闭ios系统的手机
                                        WeixinJSBridge.call("closeWindow");
                                        }, 500);
                                } else{
                                    
                                    alert(data.errmsg + 　' 请稍后重试'　)
                                    var fredirect_uri = 'http://gzh.zjnnhj.com/niuneng/register.html?community=' + area + '&device=' + deviceid + '&cerNum=' + passwd;
                                    var ffurl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx5f2850581e4e064d&redirect_uri=" + encodeURIComponent(fredirect_uri) + "&response_type=code&scope=snsapi_base&state=123#wechat_redirect";
                                    location.href = ffurl;
                                }
                            },
                            error: function(data){
                                data = JSON.parse(data)
                                alert(data.errmsg)
                                var fredirect_uri = 'http://gzh.zjnnhj.com/niuneng/register.html?community=' + area + '&device=' + deviceid + '&cerNum=' + passwd;
                                var ffurl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx5f2850581e4e064d&redirect_uri=" + encodeURIComponent(fredirect_uri) + "&response_type=code&scope=snsapi_base&state=123#wechat_redirect";
                                location.href = ffurl;
                            
                            }            
                    })
                })
            })

            </script>

    </script>
</body>

</html>
